package weixin.core.controller;

import com.github.sd4324530.fastweixin.api.TemplateMsgAPI;
import com.github.sd4324530.fastweixin.api.entity.Industry;
import com.github.sd4324530.fastweixin.api.entity.TemplateMsg;
import com.github.sd4324530.fastweixin.api.entity.TemplateParam;
import com.github.sd4324530.fastweixin.api.enums.ResultType;
import com.github.sd4324530.fastweixin.api.response.SendTemplateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lxb on 2016/4/8.
 */
@Controller
@RequestMapping("template")
public class TemplateController {
    private static final Logger LOG  = LoggerFactory.getLogger(TemplateController.class);
    @Autowired
    private TemplateMsgAPI templateMsgAPI;

    /**
     * 设置行业
     * @return
     */
    @RequestMapping("setIndustry")
    @ResponseBody
    public String setIndustry(){
        Industry industry=new Industry();
        industry.setIndustryId1("1");
        industry.setIndustryId2("4");
        ResultType resultType=templateMsgAPI.setIndustry(industry);
        return "success";

    }
    @RequestMapping("sendTemplateMes")
    @ResponseBody
    public String sendTemplateMes(){
        TemplateMsg templateMsg=new TemplateMsg();
        Map<String,TemplateParam> map=new HashMap();
        TemplateParam templateParam=new TemplateParam();
        templateParam.setColor("#173177");
        templateParam.setValue("测试值");
        map.put("001", templateParam);
        templateMsg.setTemplateId("DPPXVUs0j9oFfmqG2ysMvhCNEuhHbkkBNKYYcMniAqQ");
        templateMsg.setTouser("otPrrvqCO7nf8v98BDGKyOjDHUus");
        templateMsg.setTopcolor("#173177");
        templateMsg.setUrl("http://www.baidu.com");
        templateMsg.setData(map);
        SendTemplateResponse sendTemplateResponse=templateMsgAPI.send(templateMsg);
        TemplateMsg templateMsg1=new TemplateMsg();
        templateMsg1.setTemplateId("DPPXVUs0j9oFfmqG2ysMvhCNEuhHbkkBNKYYcMniAqQ");
        templateMsg1.setTouser("otPrrvlwjrH5S1Ov7XD7HBM5S2a8");
        templateMsg1.setTopcolor("#173177");
        templateMsg1.setUrl("http://www.baidu.com");
        templateMsg1.setData(map);
        TemplateMsg templateMsg2=new TemplateMsg();
        templateMsg2.setTemplateId("DPPXVUs0j9oFfmqG2ysMvhCNEuhHbkkBNKYYcMniAqQ");
        templateMsg2.setTouser("otPrrvjrOpepzlZeGG4CUBSKZiVk");
        templateMsg2.setTopcolor("#173177");
        templateMsg2.setUrl("http://www.baidu.com");
        templateMsg2.setData(map);
        TemplateMsg templateMsg3=new TemplateMsg();
        templateMsg3.setTemplateId("DPPXVUs0j9oFfmqG2ysMvhCNEuhHbkkBNKYYcMniAqQ");
        templateMsg3.setTouser("otPrrvicuhbyCu1hrXTdEf2JzgMI");
        templateMsg3.setTopcolor("#173177");
        templateMsg3.setData(map);
        templateMsg3.setUrl("http://www.baidu.com");
        templateMsgAPI.send(templateMsg1);
        templateMsgAPI.send(templateMsg2);
        templateMsgAPI.send(templateMsg3);
        return "success";
    }
}
